package contestseeker.visitors;

import org.htmlparser.Tag;
import org.htmlparser.tags.TableColumn;
import org.htmlparser.tags.TableRow;
import org.htmlparser.tags.TableTag;


/**
 * UVA
 * @author rush
 *
 */
public class UVA extends VisitorBase {
	public static final String NAME = "UVA";
	public static final String URL = "http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=12";
	public static final String ENCODING = "UTF-8";
	public static final String TITLE = "UVA Coming contests";

	public UVA() {
		super.URL = URL;
		super.ENCODING = ENCODING;
		super.TITLE = TITLE;
		super.NAME = NAME;
	}
	
	@Override
	public void visitTag(Tag tag)
	{
		if (tag instanceof TableTag)
		{
			TableTag table = (TableTag)tag;
			TableRow row = table.getRow(0);
			TableColumn columns[] = row.getColumns();
			
			if (columns != null && columns[0].toPlainTextString().compareTo("ID") == 0)
			{
				this.beginTable(TITLE);
				this.addHeader(row);
				for (int i = 1; i < table.getRowCount(); ++i)
				{
					row = table.getRow(i);
					columns = row.getColumns();
					if (columns.length == 5)
						this.addColumns(columns);
				}
				this.endTable();
			}
		}
	}
}
